package com.design.fitment.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ListView;

import com.design.fitment.R;
import com.design.fitment.adapter.JieXiDetailAdapter;
import com.design.fitment.entity.JieXiDetail;
import com.design.fitment.util.DesignNetworkUtil;
import com.design.fitment.util.RequestDataCallback;
import com.design.fitment.view.JieXiDetailHeaderView;
import com.google.gson.Gson;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

import java.util.ArrayList;
import java.util.List;

import cn.sharesdk.onekeyshare.OnekeyShare;

@ContentView(R.layout.activity_banner_one)
public class BannerOneActivity extends AppCompatActivity {
    @ViewInject(R.id.lv_banner)
    private ListView mlv;
    private JieXiDetail.DataEntity entity;
    private JieXiDetailHeaderView headerView;
    private JieXiDetailAdapter mAdapter;
    private List<JieXiDetail.DataEntity.ImgListEntity> mList = new ArrayList<>();
    private int bannerId;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_banner_one);
        ViewUtils.inject(this);
        Intent intent = getIntent();
        bannerId = intent.getIntExtra("bannerId",0);
        init();
        load();
    }
    private void init() {
        headerView = new JieXiDetailHeaderView(this,bannerId);
        mlv.addHeaderView(headerView);
        headerView.load();
        mAdapter = new JieXiDetailAdapter(this,mList);
        mlv.setAdapter(mAdapter);
    }
    private void load() {
        DesignNetworkUtil.getInstance().getJieXiDetail(new RequestDataCallback() {
            @Override
            public void onSuccess(String response) {
                Gson gson = new Gson();
                JieXiDetail detail = gson.fromJson(response, JieXiDetail.class);
                if (detail != null) {
                    mList.addAll(detail.getData().getImgList());
                    entity = detail.getData();
                }
                mAdapter.notifyDataSetChanged();
            }

            @Override
            public void onFailure(HttpException error) {

            }
        }, bannerId);
        headerView.load();
    }
    @OnClick(R.id.iv_banner_detail_fanhui)
    private void OnclickBack(View view){

        this.finish();
        this.overridePendingTransition(R.anim.in_from_left,R.anim.out_from_right);
    }
    @OnClick(R.id.iv_banner_detail_share)
    private void onClickShare(View view){


        OnekeyShare oks = new OnekeyShare();
        //关闭sso授权
        oks.disableSSOWhenAuthorize();

// 分享时Notification的图标和文字  2.5.9以后的版本不调用此方法
        //oks.setNotification(R.drawable.ic_launcher, getString(R.string.app_name));
        // title标题，印象笔记、邮箱、信息、微信、人人网和QQ空间使用
        oks.setTitle(entity.getName());
        // titleUrl是标题的网络链接，仅在人人网和QQ空间使用
        oks.setTitleUrl(entity.getImgUrl());
        // text是分享文本，所有平台都需要这个字段
        oks.setText(entity.getComment());
        // imagePath是图片的本地路径，Linked-In以外的平台都支持此参数
        oks.setImagePath("/sdcard/test.jpg");//确保SDcard下面存在此张图片
        // url仅在微信（包括好友和朋友圈）中使用
        oks.setUrl(entity.getImgUrl());
        // comment是我对这条分享的评论，仅在人人网和QQ空间使用
        oks.setComment("我是测试评论文本");
        // site是分享此内容的网站名称，仅在QQ空间使用
        oks.setSite("设计本");
        // siteUrl是分享此内容的网站地址，仅在QQ空间使用
        oks.setSiteUrl(entity.getComment());

        // 启动分享GUI
        oks.show(this);

    }
}
